package com.cyy.springbootinit.service.impl;

import com.cyy.springbootinit.model.vo.EleFeeRuleResponseVo;
import com.cyy.springbootinit.model.vo.WaterFeeRuleResponseVo;
import com.cyy.springbootinit.service.EleFeeRuleService;
import com.cyy.springbootinit.service.WaterFeeRuleService;
import com.cyy.springbootinit.utils.DroolsHelper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@SuppressWarnings({"unchecked", "rawtypes"})
@RequiredArgsConstructor
public class EleFeeRuleServiceImpl implements EleFeeRuleService {

    private final KieContainer kieContainer;
    private static final String RULES_CUSTOMER_RULES_DRL = "rules/EleWaterFeeRule.drl";
    @Override
    public EleFeeRuleResponseVo calculateOrderFee(Double count) {
        KieSession kieSession = DroolsHelper.loadForRule(RULES_CUSTOMER_RULES_DRL);
        //封装返回对象
        EleFeeRuleResponseVo eleFeeRuleResponseVo = new EleFeeRuleResponseVo();
        kieSession.setGlobal("eleFeeRuleResponseVo", eleFeeRuleResponseVo);
        // 设置订单对象
        kieSession.insert(count);
        // 触发规则
        kieSession.fireAllRules();
        // 中止会话
        kieSession.dispose();
        log.info("计算结果：{}",eleFeeRuleResponseVo.getTotalAmount() );

        //封装返回对象
        return eleFeeRuleResponseVo;
    }
}
